{extend name="public:base"}
{block name="body"}
<body class="pear-container">
	<div class="layui-card">
		<div class="layui-card-body">
			<form class="layui-form" action="">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-inline">
                        <input type="text" name="keywords" placeholder="标题|标识" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">分类</label>
                    <div class="layui-input-inline">
                        <select name="cate_id">
                            <option value="">所有分类</option>
                            {volist name="category" id="vo"}
                            <option value="{$vo.id}">{$vo.title}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">推荐类型</label>
                    <div class="layui-input-inline">
                        <select name="commend">
                            <option value="">所有类型</option>
                            <option value="index">首推</option>
                            <option value="hot">热荐</option>
                            <option value="new">新品</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-inline">
                        <select name="status">
                            <option value="">选择状态</option>
                            <option value="1">启用</option>
                            <option value="0">禁用</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="table-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
			</form>
		</div>
	</div>
	<div class="layui-card">
		<div class="layui-card-body">
			<table id="table-list" lay-filter="table-list"></table>
		</div>
	</div>
</body>
{/block}
{block name="custome"}
	<script type="text/html" id="table-toolbar">
		<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
			<i class="layui-icon layui-icon-add-1"></i>
			新增
		</button>
		<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
			<i class="layui-icon layui-icon-delete"></i>
			删除
		</button>
	</script>
	<script type="text/html" id="table-bar">
        <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="site" title="{{ d.module_id== 1 ? '设置经纪人' : '设置公司' }}"><i class="icon pear-icon pear-icon-setting"></i></button>
		<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button>
		<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
	</script>
	{/block}
{block name="script"}
<script type="text/html" id="table-status">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="table-status" {{ d.status== 1 ? 'checked' : '' }} />
</script>
<script type="text/html" id="table-title">
    <div class="thumb" style="width:30px;height:30px;display:inline-block;"><img src="{{ d.thumb }}" width="30" height="30"></div><span>{{ d.title }}</span>
</script>
<script type="text/html" id="table-icon">
    {{# if(d.icon){ }}
    <div class="thumb" style="width:30px;height:30px;display:inline-block;"><img src="{{ d.icon }}" width="30" height="30"></div>
    {{# }else{ }}
    --
    {{# } }}
</script>
<script type="text/html" id="table-create_time">
        {{layui.util.toDateString(d.create_time, 'yyyy-MM-dd HH:mm')}}
</script>
<script type="text/html" id="table-tags">
    {{# let tags = d.tags?d.tags.split(','):''}}
    {{# if (tags != ''){ }}
    {{# layui.each(tags, function(index, item){ }}
    <span class="layui-badge layui-bg-blue">{{ item }}</span>
    {{# }) }}
    {{# } }}
</script>
<script>
    layui.use(['table', 'form', 'jquery', 'common'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;
        let cols = [
            [{
                type: 'checkbox'
            },
            {
                title: 'ID',
                field: 'id',
                align: 'center',
                width: 150
           
            },
            {
                title: '产品名称',
                field: 'title',
   
                templet:'#table-title',
                width: 280
           
            },
            {
                title: '产品图标',
                field: 'icon',
                templet:'#table-icon',
                align: 'center',
                width: 100
           
            },
            {
                title: '所属分类',
                field: 'parent_name',
                align: 'center',
                width: 100
            },
            {
                title: '模块属性',
                field: 'module_title',
                align: 'center',
                width: 100
               
            },
            {
                title: '产品标签',
                field: 'tags',
                align: 'center',
                templet: '#table-tags',
               
            },
            {
                title: '价格描述',
                field: 'price',
                align: 'center',
                width: 150
            },
            {
                title: '排序',
                field: 'sort',
                align: 'center',
                width: 100
            },
            
            {
                title: '状态',
                field: 'status',
                align: 'center',
                templet: '#table-status',
                width: 150
            },
            {
                title: '操作',
                toolbar: '#table-bar',
                align: 'center',
                width: 200
            }
            ]
        ]

        table.render({
            elem: '#table-list',
            url: '{:url("index")}',
            parseData: function(res){ 
            return {
            "code": res.code, //解析接口状态
            "msg": res.message, //解析提示文本
            "count": res.data.total, //解析数据长度
            "data": res.data.data //解析数据列表
            }},
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#table-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter']
        });
        form.on('submit(table-query)', function (data) {
            table.reload('table-list', {
                where: data.field
            })
            return false;
        });
        table.on('tool(table-list)', function (obj) {
            if (obj.event === 'remove') {
                common.remove(obj,"{:url('batch')}");
            }
            if (obj.event === 'edit') {
                common.modalo('{:url("edit")}?ids=' + obj.data['id'],'编辑','90%');
            }
            if (obj.event === 'site'){
                common.modalo('{:url("site")}?ids=' + obj.data['id'],'设置','750px');
            }
        });
        $(document).on('click','.thumb',function(){
            var src = $(this).find('img').attr('src');
 
            layer.open({
                type: 1,
                title: false,
                shade: 0.8,
                closeBtn: 0,
                shadeClose: true,
                content: '<img src="'+src+'">'
            });
        })
        table.on('toolbar(table-list)', function (obj) {
            if (obj.event === 'add') {
               common.modalo('{:url("add")}','新增','90%');
            } else if (obj.event === 'refresh') {
                common.refresh();
            } else if (obj.event === 'batchRemove') {
                common.batchRemove(obj,"{:url('batch')}");
            }
        });
        form.on('switch(table-status)', function (data) {
            let loading = layer.load();
            let field = {};
            field['id']=data.value;
            field[data.elem.name] = data.elem.checked?"1":"0";
            $.ajax({
                url: '{:url("change")}',
                type: 'post',
                data: field,
                success: function (result) {
                    layer.close(loading);
                    if (result.code == 1) {
                        layer.msg('操作成功', {
								icon: 1,
								time: 1000
							})
                    } else {
                        layer.msg(result.msg, {
								icon: 2,
								time: 1000
							})
                    }
                }
            })
        });  
    })
</script>
{/block}